Skip to content

feat: add pi coding agent provider#1

Open
hev wants to merge 1 commit intomainfrom
feat/pi-provider
Open

feat: add pi coding agent provider#1
hev wants to merge 1 commit intomainfrom
feat/pi-provider

Conversation

@hev
Copy link
Copy Markdown
Owner

@hev hev commented Mar 15, 2026

Add belaykit/pi package — a provider that wraps the pi coding agent CLI as a belaykit.Agent implementation.

What it does

Runs pi --mode json --no-session -p <prompt> and parses the JSONL event stream, mapping pi's events to belaykit's Event types:

pi event belaykit event
session EventSystem
turn_start EventAssistantStart
message_update (text_delta) EventAssistant
tool_execution_start EventToolUse
tool_execution_end EventToolResult
message_end (accumulates usage/cost/model)
agent_end EventResult

Pi-specific options

Beyond the standard WithExecutable, WithDefaultModel, WithDefaultEventHandler, WithObservability:

  • WithDefaultProvider — set LLM provider (anthropic, openai, google, etc.)
  • WithDefaultThinking — set thinking level (off, minimal, low, medium, high, xhigh)
  • WithTools / WithNoTools — control which built-in tools are available
  • WithExtension — load pi extensions
  • WithWorkDir — set the working directory for the pi process

Usage

client := pi.NewClient(
    pi.WithDefaultModel("sonnet:high"),
    pi.WithWorkDir("/path/to/project"),
)

res, err := client.Run(ctx, "List all .ts files in src/")

Token usage

Unlike shelling out to Claude CLI (which reports cost directly in its result event), pi reports per-message usage in message_end events with input/output token counts and cost breakdowns. The provider accumulates these across all messages and passes real numbers to RecordCompletion.

Files

  • pi/pi.goClient struct, Run implementation, JSONL parser
  • pi/options.goClientOption functions
  • pi/models.goPricingForModel, ContextWindowForModel helpers

Add belaykit/pi package that wraps the pi CLI (github.com/badlogic/pi-mono)
as a belaykit.Agent implementation.

- Runs pi in --mode json for structured JSONL event streaming
- Maps pi events to belaykit EventTypes (assistant, tool_use, tool_result, etc.)
- Extracts real token usage and cost from pi's usage data in message_end events
- Supports pi-specific options: provider, thinking level, tool control, extensions, workdir
- Includes PricingForModel/ContextWindowForModel for common models across providers
- Full observability integration via RecordCompletion with actual token counts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant